<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
	@$mysqli = new mysqli($_POST['host'], $_POST['user'],  $_POST['passwrod']);
	!$mysqli->connect_error or  die('Connect Error (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error);
	$mysqli->server_info > 5.0 or die('mysql版本必须5.0以上');
	$mysqli->query("SET NAMES 'UTF8'");
	if (!$mysqli->select_db($_POST['db_name'])) {
		$create_sql='CREATE DATABASE IF NOT EXISTS '.$_POST['db_name'].' DEFAULT CHARACTER SET utf8;';
		$mysqli->query($create_sql) or die('数据库创建失败');
		$mysqli->select_db($_POST['db_name']);
	}
	$sql_string = file_get_contents('./db.sql');
	$sql_array = preg_split("/;[\r\n]+/", $sql_string);
	foreach ($sql_array as $key => $value) {
		if (!empty($value)) {
			$mysqli->query($value);
		}
	}

	$mysqli->close();
	require './success.html';
}
